#import "ShiftExifController.h"

@implementation ShiftExifController

//------------------------------------------------------------------------------
- (id) initWithDate:(NSDate*) date  note:(NSString*)note  exif:(BOOL) exif
{
	self = [super init];
	if (nil != self)
	{
		startDate = date;
		[startDate retain];

		displayNote = note;
		[displayNote retain];

		useOnExif = exif;
	}

	return self;
}

//------------------------------------------------------------------------------
- (void) dealloc
{
	[displayNote release];
	[startDate release];
	[super dealloc];
}

//------------------------------------------------------------------------------
- (void) awakeFromNib
{
	[mainWindow setTitle:
		(YES == useOnExif) 
			? NSLocalizedString(@"Shift EXIF Date", @"shiftExifDate.title") 
			: NSLocalizedString(@"Shift File Date", @"shiftFileDate.title")];


	NSString *instructions = [NSString stringWithFormat: 
			[txtInstructions stringValue],
			(YES == useOnExif) ? @"EXIF" : @"file"];
	[txtInstructions setTitleWithMnemonic: instructions];

	if (NO == useOnExif)
	{
		[changeFileDate setHidden: YES];
	}
	else
	{
		[changeFileDate setState: YES];
	}

	[txtNote setTitleWithMnemonic:displayNote];
	[datePicker setDateValue: startDate];

	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4];
	[dateFormatter setDateStyle: NSDateFormatterShortStyle];
	[dateFormatter setTimeStyle: NSDateFormatterMediumStyle];
	NSString *originalDate = [dateFormatter stringForObjectValue: startDate];
	[dateFormatter release];

	[txtOriginalDate setTitleWithMnemonic: originalDate];
}

//------------------------------------------------------------------------------
- (IBAction)cancelClicked:(id)sender
{
	[NSApp abortModal];
	[mainWindow close];
}

//------------------------------------------------------------------------------
- (IBAction)okClicked:(id)sender
{
	updateFileDate = [changeFileDate state];
	NSDate *newDate = [datePicker dateValue];
	delta = [newDate timeIntervalSinceDate: startDate];

	[NSApp stopModal];
	[mainWindow close];
}

//------------------------------------------------------------------------------
- (BOOL) updateFileDate
{
	return updateFileDate;
}

//------------------------------------------------------------------------------
- (NSTimeInterval) delta
{
	return delta;
}

//------------------------------------------------------------------------------
- (NSWindow*) mainWindow
{
	return mainWindow;
}

@end
